package cc.forgemod.customicon.common.util;

import cc.forgemod.customicon.asm.side.ServerEmpty;
import cc.forgemod.customicon.common.icon.Icon;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;

public class CompaTool {

    public static final Item AIR = Items.AIR;

    public static Item getByNameOrId(String tStr) {
        return Item.getByNameOrId(tStr);
    }

    public static boolean isValidStack(ItemStack pStack) {
        return pStack != null && isValidItem(pStack.getItem());
    }

    public static boolean isValidItem(Item pItem) {
        return pItem != null && pItem.delegate != null && pItem != AIR;
    }

    public static String getRegistryName(Item pItem) {
        return pItem.getRegistryName().toString();
    }

    public static int getStackMeta(ItemStack pStack) {
        return pStack.getMetadata();
    }

    public static EntityPlayerSP getClientPlayer() {
        return Minecraft.getMinecraft().player;
    }

    public static WorldClient getClientWorld() {
        return Minecraft.getMinecraft().world;
    }

    public static boolean isServer() {
        return FMLCommonHandler.instance().getSide() == Side.SERVER;
    }

    public static boolean isClient() {
        return FMLCommonHandler.instance().getSide() == Side.CLIENT;
    }

    public static void syncTask(Runnable pTask) {
        Minecraft.getMinecraft().addScheduledTask(pTask);
    }

    @ServerEmpty
    public static void onIconUpdate(Icon pNew, Icon pOld) {}

    public static void onIconRemove(Icon pRemove) {}

}
